package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduAssignmentQuestionMapper;
import com.zenith.edu.po.domain.EduAssignmentQuestion;
import com.zenith.edu.po.dto.EduAssignmentQuestionDTO;
import com.zenith.edu.po.vo.EduAssignmentQuestionVO;
import com.zenith.edu.service.EduAssignmentQuestionService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduAssignmentQuestionServiceImpl extends ServiceImpl<EduAssignmentQuestionMapper, EduAssignmentQuestion> implements EduAssignmentQuestionService {
    
    @Override
    public EduAssignmentQuestionVO createAssignmentQuestion(EduAssignmentQuestionDTO dto) {
        EduAssignmentQuestion assignmentQuestion = new EduAssignmentQuestion();
        BeanUtils.copyProperties(dto, assignmentQuestion);
        this.save(assignmentQuestion);
        
        EduAssignmentQuestionVO vo = new EduAssignmentQuestionVO();
        BeanUtils.copyProperties(assignmentQuestion, vo);
        return vo;
    }
    
    @Override
    public EduAssignmentQuestionVO getAssignmentQuestionById(Long id) {
        EduAssignmentQuestion assignmentQuestion = this.getById(id);
        if (assignmentQuestion == null) {
            return null;
        }
        
        EduAssignmentQuestionVO vo = new EduAssignmentQuestionVO();
        BeanUtils.copyProperties(assignmentQuestion, vo);
        return vo;
    }
    
    @Override
    public EduAssignmentQuestionVO updateAssignmentQuestion(EduAssignmentQuestionDTO dto) {
        EduAssignmentQuestion assignmentQuestion = new EduAssignmentQuestion();
        BeanUtils.copyProperties(dto, assignmentQuestion);
        this.updateById(assignmentQuestion);
        
        EduAssignmentQuestionVO vo = new EduAssignmentQuestionVO();
        BeanUtils.copyProperties(assignmentQuestion, vo);
        return vo;
    }
    
    @Override
    public boolean deleteAssignmentQuestion(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduAssignmentQuestionVO> getAssignmentQuestionList() {
        List<EduAssignmentQuestion> assignmentQuestionList = this.list();
        return assignmentQuestionList.stream().map(assignmentQuestion -> {
            EduAssignmentQuestionVO vo = new EduAssignmentQuestionVO();
            BeanUtils.copyProperties(assignmentQuestion, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}